class DbFixLanguage2 < ActiveRecord::Migration
  def self.up
    add_column :country_localizations, :language_id, :integer
    add_column :rss_links, :language_id, :integer
    portuguese = Language.create(:code => "pt", :name => "Português")
    english = Language.create(:code => "en", :name => "English")
    CountryLocalization.all() do |countryLocalization|
      case countryLocalization.language
      when 'pt'
        countryLocalization.language_id = portuguese.id
      else
        countryLocalization.language_id = english.id
      end
    end
    RssLink.all() do |rssLink|
      case rssLink.language
      when 'pt'
        rssLink.language_id = portuguese.id
      else
        rssLink.language_id = english.id
      end
    end
    remove_column :country_localizations, :language
    remove_column :rss_links, :language
  end

  def self.down
    add_column :country_localizations, :language, :string
    add_column :rss_links, :language, :string
    remove_column :country_localizations, :language_id, :integer
    remove_column :rss_links, :language_id, :integer
  end
end
